﻿using FrontEnd.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace FrontEnd.Classes
{
	public class DatabaseMenuBuilder : INodeMenuBuilable
	{
		public ContextMenu BuildMenu(Node n)
		{
			var cm = new ContextMenu();
			cm.Items.Add(new MenuItem() { Header = "Attach", Command = MyCommands.Attach });
			cm.Items.Add(new MenuItem() { Header = "Check Integrity", Command = MyCommands.CheckIntegrity, CommandParameter = n });
			cm.Items.Add(new MenuItem() { Header = "Vacuum", Command = MyCommands.Vacuum });
			return cm;
		}

		public List<NodeType> GetApplicableNodeTypes()
		{
			return new List<NodeType>() { NodeType.Database };
		}
	}

	public class AttachedDatabaseMenuBuilder : INodeMenuBuilable
	{
		public ContextMenu BuildMenu(Node n)
		{
			var cm = new ContextMenu();
			cm.Items.Add(new MenuItem() { Header = "Detach", Command = MyCommands.Detach, CommandParameter = n.Title });
			return cm;
		}

		public List<NodeType> GetApplicableNodeTypes()
		{
			return new List<NodeType>() { NodeType.AttachedDatabase };
		}
	}

	public class TableViewMenuBuilder : INodeMenuBuilable
	{
		public ContextMenu BuildMenu(Node n)
		{
			var cm = new ContextMenu();
			cm.Items.Add(new MenuItem() { Header = "Select TOP 1000", Command = MyCommands.SelectTop, CommandParameter = n.Title });
			cm.Items.Add(new MenuItem() { Header = "Show CREATE SQL", Command = MyCommands.ShowCreateSQL, CommandParameter = n });
			return cm;
		}

		public List<NodeType> GetApplicableNodeTypes()
		{
			return new List<NodeType>() { NodeType.Table, NodeType.View };
		}
	}

	public class IndexMenuBuilder : INodeMenuBuilable
	{
		public ContextMenu BuildMenu(Node n)
		{
			var cm = new ContextMenu();
			cm.Items.Add(new MenuItem() { Header = "Show CREATE SQL", Command = MyCommands.ShowCreateSQL, CommandParameter = n });
			return cm;
		}

		public List<NodeType> GetApplicableNodeTypes()
		{
			return new List<NodeType>() { NodeType.Index };
		}
	}

	public class TriggerMenuBuilder : INodeMenuBuilable
	{
		public ContextMenu BuildMenu(Node n)
		{
			var cm = new ContextMenu();
			cm.Items.Add(new MenuItem() { Header = "Show CREATE SQL", Command = MyCommands.ShowCreateSQL, CommandParameter = n });
			return cm;
		}

		public List<NodeType> GetApplicableNodeTypes()
		{
			return new List<NodeType>() { NodeType.Trigger };
		}
	}
}
